Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Refine behavior_binding_event, nested trans #2848

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Nick-Munnich
Copy link
Contributor

@Nick-Munnich Nick-Munnich commented Feb 27, 2025

This PR essentially does multiple things in one commit. These are all quite linked to one another, I wasn't quite able to untangle them from each other.

  • Refactors the existing sensor code, making encoder rotational tracking happen outside of behaviors and inside sensors.c.
  • Revamps zmk_behavior_binding_event so that it is actually a zmk event, i.e. is raised and managed by event_manager.
  • Allow the nesting of &trans inside of other behaviors, getting rid of ZMK_BEHAVIOR_TRANSPARENT in the process.

Taking the explanation from #573:
We currently have the following events

  • position_state_changed
    • keycode_state_changed
    • layer_state_changed

What is missing from this event flow are behavior bindings. This means they can not be observed like other events.

  • position_state_changed
    • behavior_binding_event
      • keycode_state_changed
      • layer_state_changed

This refactor/feat will allow for much more advanced and elegant handling in the future. My goal is to use this to rework combos a bit further. Nesting &trans is also a benefit that should not be underestimated, it will make things like home-row mods much easier to set up. The sensor refactor should allow further work on that part to be simpler as well.

Needs documentation and lots of testing, particularly around the encoder bits as the tests we have are very rudimentary. There are likely some stylistic bits that could use tidying up as well.

Closes: #573, #532, #2368

PR check-list

  • Branch has a clean commit history
  • Additional tests are included, if changing behaviors/core code that is testable.
  • Proper Copyright + License headers added to applicable files (Generally, we stick to "The ZMK Contributors" for copyrights to help avoid churn when files get edited)
  • Pre-commit used to check formatting of files, commit messages, etc.
  • Includes any necessary documentation changes.

Adds some encoder tests for rotating, and basic layers.
Mock Kscans don't seem to interact nicely, slightly on the hacky side.
However, better to have hacky tests than no tests.
@Nick-Munnich Nick-Munnich requested a review from a team as a code owner February 27, 2025 22:33
@Nick-Munnich Nick-Munnich added core Core functionality/behavior of ZMK behaviors encoders refactor labels Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
behaviors core Core functionality/behavior of ZMK encoders refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant